package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UnionInfoBean;
import com.koron.css2.clientCenter.mapper.UnionInfoMapper;
import com.koron.css2.clientCenter.queryBean.UnionInfoQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class UnionInfoList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try{
            UnionInfoQueryBean queryBean = JsonUtils.objectToPojo(req.getData(),UnionInfoQueryBean.class);
            UnionInfoMapper unionInfoMapper = factory.getMapper(UnionInfoMapper.class);

            PageHelper.startPage(queryBean.getPage(), queryBean.getPageCount());
            List<UnionInfoBean> unionInfoBeanList = unionInfoMapper.queryList(queryBean);

            @SuppressWarnings("rawtypes")
            MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
            info.setData(new PageInfo<>(unionInfoBeanList));
            return info;

        }catch (Exception e){
            logger.error("查询失败" + e.getMessage(), e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
        }

    }
}
